package com.lanou3g.k12.service.impl;

import com.lanou3g.k12.entity.ArticleCategory;
import com.lanou3g.k12.mapper.ArticleCategoryMapper;
import com.lanou3g.k12.service.ArticleCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ArticleCategoryServiceImpl implements ArticleCategoryService {

    @Autowired
    ArticleCategoryMapper articleCategoryMapper;



    // keyword查找并分页
    @Override
    public List<ArticleCategory> findByKeyword(Integer page, Integer size, String keyword) {

        List<ArticleCategory> articleCategories = articleCategoryMapper.findByKeyword('%' + keyword + '%');

        return articleCategories;
    }

    // 查找所有
    @Override
    public List<ArticleCategory> findAll(Integer page, Integer size) {

        List<ArticleCategory> articleCategories = articleCategoryMapper.findAll();
          return articleCategories;
    }

    // 根据id批量删除
    @Override
    public void deleteArticleCategoryByIds(Integer[] ids) {

        articleCategoryMapper.deleteArticleCategoryByIds(ids);
    }

    // 添加
    @Override
    public void insertArticleCategory(String name, String remark, Integer status) {

        Date date = new Date();
        ArticleCategory articleCategory = new ArticleCategory();
        articleCategory.setName(name);
        articleCategory.setRemark(remark);
        articleCategory.setCreateTime(date);
        articleCategory.setUpdateTime(date);
        articleCategory.setStatus(status);

        articleCategoryMapper.insertArticleCategory(articleCategory);
    }

    // 根据id查找
    @Override
    public ArticleCategory findArticleCategoryById(Long id) {
        ArticleCategory articleCategory = articleCategoryMapper.findArticleCategoryById(id);
        return articleCategory;
    }


    // 根据id修改
    @Override
    public void updateArticleCategoryById(Long id, String name, String remark, Integer status) {
        ArticleCategory articleCategoryById = articleCategoryMapper.findArticleCategoryById(id);
        Date date = new Date();
        articleCategoryById.setUpdateTime(date);
        articleCategoryById.setName(name);
        articleCategoryById.setRemark(remark);
        articleCategoryById.setStatus(status);

        articleCategoryMapper.updateArticleCategory(articleCategoryById);
    }


    // 根据id删除
    @Override
    public void deleteArticleCategoryById(Long id) {
        articleCategoryMapper.deleteArticleCategoryById(id);
    }






    @Override
    public List<ArticleCategory> findByKeywordForBackend(Integer page, Integer size, String keyword) {

        List<ArticleCategory> articleCategories = articleCategoryMapper.findByKeywordForBackend('%' + keyword + '%');

        return articleCategories;
    }

    @Override
    public List<ArticleCategory> findAllForBackend(Integer page, Integer size) {

        List<ArticleCategory> articleCategories = articleCategoryMapper.findAllForBackend();
        return articleCategories;

    }

    @Override
    public ArticleCategory findByIdForBackend(Long id) {
        ArticleCategory articleCategory = articleCategoryMapper.findByIdForBackend(id);
        return articleCategory;
    }


}
